//
//  VideoDecoder.h
//  TTPlayerLibrary
//
//  Created by TTPlayer on 11. 10. 14..
//  Copyright (c) 2011 ItBacc. All rights reserved.
//

#import <Foundation/Foundation.h>

#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"

#include "libavdevice/avdevice.h"
#include "libavfilter/avfilter.h"

#define DECODING_FMT PIX_FMT_YUV420P

typedef struct VideoState{
    uint8_t *videoBuffer;
    AVFrame *frame;
    AVFrame *frame2;
    
    int videoBufferSize;
    int64_t videoPTS;
    
    int audioBufferAllocSize;
    int64_t audioPTS;
    uint8_t *audioBuffer;
    int audioBufferSize;
    
    BOOL isAudio;
    float videoWidth,videoHeight;
    float fps;
    float audioTimeBase,videoTimeBase;
    int64_t duration;
    float sampleRate;
    int retCode;
} VideoState;

@interface VideoDecoder : NSObject{
    VideoState *videoState;
    
    AVFormatContext *formatCtx;
    AVCodecContext *videoCodecCtx;
    AVCodec *videoCodec;
    int videoStreamIdx;
    
    AVCodecContext *audioCodecCtx;
    AVCodec *audioCodec;    
    int audioStreamIdx;
    
    struct SwsContext *imgConvertCtx;
    int videoBufferSize;
}

- (id)initWithFilePath:(NSString*)filePath;
- (VideoState*)decodeFrame;
- (BOOL)seekToTime:(int64_t)pos;

@end
